Skip to content

[composer-based] Bond RemoveExpectAnyFromMockRector to PHPUnit 11+ - #756

Merged
TomasVotruba merged 1 commit into
mainfrom
bond-remove-expect-any-phpunit11
Aug 1, 2026
Merged

[composer-based] Bond RemoveExpectAnyFromMockRector to PHPUnit 11+#756
TomasVotruba merged 1 commit into
mainfrom
bond-remove-expect-any-phpunit11

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

RemoveExpectAnyFromMockRector had no version bond at all — it was registered only in the phpunit-code-quality set and fired on any PHPUnit version.

The rule really belongs to the PHPUnit 11 mock-to-stub story: stripping expects($this->any()) leaves the mock with zero expectations, which is exactly what unblocks ExpressionCreateMockToCreateStubRector, PropertyCreateMockToCreateStubRector and friends.

So it now implements ComposerPackageConstraintInterface with phpunit/phpunit >=11.0, and is registered in config/sets/composer-based.php next to the other mock/stub rules. It stays in the code-quality set as well, same as BareCreateMockAssignToDirectUseRector.

What the rule does:

 use PHPUnit\Framework\TestCase;

 class SomeClass extends TestCase
 {
     public function test()
     {
         $translator = $this->createMock(SomeClass::class);
-        $translator->expects($this->any())
-            ->method('trans')
+        $translator->method('trans')
             ->willReturn('translated max {{ max }}!');
     }
 }

Removing expects($this->any()) leaves the mock without expectations,
which is what unblocks the PHPUnit 11 mock-to-stub rules. Bond the rule
to "phpunit/phpunit" >=11.0 and register it in the composer-based set.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 1, 2026 08:52
@TomasVotruba
TomasVotruba merged commit e68085d into main Aug 1, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the bond-remove-expect-any-phpunit11 branch August 1, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant